﻿namespace MobileTrack.Core.Data
{
    using System.Data.Entity;
    using MobileTrack.Core.Model;

    public class MobileTrackContext : DbContext
    {
        public MobileTrackContext()
        {
        }

        public MobileTrackContext(string nameOrConnectionString)
            : base(nameOrConnectionString)
        {
        }

        public DbSet<Celular> Celulares { get; set; }

        public DbSet<Abono> Abonos { get; set; }

        public DbSet<Seguimiento> Seguimientos { get; set; }

        public DbSet<Venta> Ventas { get; set; }

        public DbSet<Sucursal> Sucursales { get; set; }

        public DbSet<Proveedor> Proveedores { get; set; }

        public DbSet<Marca> Marcas { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            if (modelBuilder != null)
            {
                modelBuilder.Entity<Venta>().HasRequired(v => v.Celular).WithMany().WillCascadeOnDelete(false);
                modelBuilder.Entity<Celular>().HasRequired(v => v.Marca).WithMany(m => m.Celulares).WillCascadeOnDelete(false);
            }
        }
    }
}
